import { registerMicroApps, start, initGlobalState } from 'qiankun'
import qianKunVue from '@/views/qiankun/index'
const action = initGlobalState({ asdf: 1 })
const loadingFn = (val) => {
  console.log(val)
}
const getUserInfo = (val) => {
  console.log(val)
}

const list = [
  {
    path: '/app1/:page*',
    name: 'app1',
    entry: '//localhost:8081/',
    container: '#qiankundom',
    activeRule: ['/app1', '/app2'],
    // props: action,
    meta: {
      title: "app1",
      hasAside: true,
      icon: require("@/assets/icon/logo.png"),
      // keepAlive: true,
    },
    children: []
  },
  // {

  //   path: '/vpc',
  //   name: 'vpc',
  //   meta: {
  //     title: 'router.index.vpc',
  //     hasAside: true,
  //     icon: 'icon-a-VPCxunizhuanyouwangluo',
  //     parentKey: routerCategoryEnum.network
  //   },
  //   children: []
  // }
]
const microAppStart = () => {

  registerMicroApps(list, {
    beforeLoad: [
      (app) => {
        // console.log('[LifeCycle] before load %c%s', 'color: green;', app.name)
      }
    ],
    beforeMount: [
      async (app) => {
        // console.log('[LifeCycle] before mount %c%s', 'color: green;', app.name)
        // const token = getToken()
        // if (token) {
        //     await store.dispatch('login', token)
        // }
      }
    ],
    afterUnmount: [
      (app) => {
        // console.log('[LifeCycle] after unmount %c%s', 'color: green;', app.name)
        // resetRouter();
      }
    ]
  })
  start({
    prefetch: true,
    singular: true
  })
}
export const qiankunRouter = () => {
  return list.map((item, index) => ({
    // path: '/' + item.name,
    // name: item.name,
    // meta: item.meta,
    ...item,
    component: qianKunVue
  }))
}
export default microAppStart